package com.producer.controller;

import com.producer.service.TestService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class KafkaController {
    @Autowired
    private TestService testService;

    @GetMapping("/send/{type}")
    public String sendMessageToKafka(@PathVariable int type) {
        if(type == 1){
            // 模拟执行事务未开启的业务逻辑
            testService.executeServiceNoTranscational(type);
        }else{
            // 模拟执行事务开启的业务逻辑
            testService.executeService(type);
        }

        //模拟还要执行其他的service
        System.out.println("执行其他业务逻辑");
        return "ok";
    }
}